package com.hrzyit.base.rx

import com.hrzyit.base.common.ResultCode
import com.hrzyit.base.data.protocol.BaseResp
import io.reactivex.Observable
import io.reactivex.functions.Function

//import rx.Observable
//import rx.functions.Func1

/**
 * Rx: Boolean类型转换封装
 * @author YangWei
 * @date 2019/3/27
 */
class BaseFuncBoolean<T> : Function<BaseResp<T>, Observable<Boolean>> {
    override fun apply(t: BaseResp<T>): Observable<Boolean> {
        if (t.code != ResultCode.SUCCESS) {
            return Observable.error(BaseException(t.code, t.msg))
        }
        return Observable.just(true)
    }
    // Rx 1.2.0
//    override fun call(t: BaseResp<T>): Observable<Boolean> {
//        if (t.code != ResultCode.SUCCESS) {
//            return Observable.error(BaseException(t.code, t.msg))
//        }
//
//        return Observable.just(true)
//    }
}